#!/usr/bin/env python3

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from config import email

def SendEmail(message,subject,toad):
    sender='admin@bishop-web.com'
    to=toad
    mail_coding = 'windows-1251'
    #-----------------------
    msg=MIMEMultipart()
    msg['Subject']=subject
    msg['From']=sender
    msg['To']=to
    #-----------------------
    MIME_text=MIMEText(message.encode('cp1251',errors='ignore'),'plain',mail_coding)
    msg.set_charset(mail_coding)
    msg.attach(MIME_text)
    #-----------------------
    serv_host='smtp.bishop-web.com'
    port='587'
    #-----------------------
    log=email['login']
    pas=email['password']
    #-----------------------
    fro='admin@bishop-web.com'
    #-----------------------
    server=smtplib.SMTP(serv_host,port)
    server.starttls()
    server.login(log,pas)
    server.sendmail(fro, toad, msg.as_string())
    server.quit()






